package ext;

import image.Image3;
import image.ImageGroup;
import image.disk.FormatPNG;
import image.synth.Synthesizer;
import math.vec2i;
import math.vec3;

public class ProgAverage2
{
    
    public static void main(String[] args)
    {
        Synthesizer synth = new Synthesizer();
        
        String file0 = "MERGE_INPUT_0";
        String file1 = "MERGE_INPUT_1";
        String fileExport = "MERGE_EXPORT";
        
        Image3 img0 = FormatPNG.load(file0);
        Image3 img1 = FormatPNG.load(file1);
        if (!img0.mSize.close(img1.mSize, 0))
        {
            System.err.println("Images are not the same size.");
            return;
        }
        vec2i size = img0.mSize;
        
        ImageGroup target = new ImageGroup(2);
        target.attach(0, img0);
        target.attach(1, img1);
        synth.rTarget = target;
        
        PSMerge psm = new PSMerge();
        psm.mMergeOp = PSMerge.sMERGE_ADD;
        psm.mTargetI3_A = 0;
        psm.mTargetI3_B = 1;
        psm.mTargetI3_OUT = 0;
        synth.computeImage(psm, vec2i.ZERO, size);
        
        Image3.scaleAll(target.image3(0), new vec3(0.5));
        FormatPNG.save(target.image3(0), fileExport);
    }
    
}
